package com.kainitram.drivebook.models;

import java.util.Random;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.kainitram.morm.ModelBase;

/**
 * Car databases entity.
 * 
 * @author Mino
 * 
 */
@DatabaseTable
public class Car extends ModelBase {

	public static final String EVC_FIELD_NAME = "evc";
	
	@DatabaseField(canBeNull = false, uniqueIndex = true, columnName = EVC_FIELD_NAME)
	private String evc;
	@DatabaseField
	private double tachometerState;
	@DatabaseField
	private double tankSize;
	@DatabaseField
	private eFuelType fuelType;
	@DatabaseField
	private double consumptionInTown;
	@DatabaseField
	private double consumptionOutOfTown;
	@DatabaseField
	private double consumptionCombine;
	@DatabaseField(generatedId = true)
	private long _id = -1;

	@Override
	public long getID() {
		return _id;
	}
	

	@Override
	public void setID(long id) {
		_id = id;
	}
	

	/**
	 * @return the evc
	 */
	public String getEvc() {
		return evc;
	}

	/**
	 * @param evc
	 *            the spz to set
	 */
	public void setEvc(String spz) {
		this.evc = spz;
	}

	/**
	 * @return the tachometerState
	 */
	public double getTachometerState() {
		return tachometerState;
	}

	/**
	 * @param tachometerState
	 *            the tachometerState to set
	 */
	public void setTachometerState(double tachometerState) {
		this.tachometerState = tachometerState;
	}

	/**
	 * @return the tankSize
	 */
	public double getTankSize() {
		return tankSize;
	}

	/**
	 * @param tankSize
	 *            the tankSize to set
	 */
	public void setTankSize(double tankSize) {
		this.tankSize = tankSize;
	}

	/**
	 * @return the fuelType
	 */
	public eFuelType getFuelType() {
		return fuelType;
	}

	/**
	 * @param fuelType
	 *            the fuelType to set
	 */
	public void setFuelType(eFuelType fuelType) {
		this.fuelType = fuelType;
	}

	public double getmConsumptionInTown() {
		return consumptionInTown;
	}

	public void setConsumptionInTown(double consumptionInTown) {
		this.consumptionInTown = consumptionInTown;
	}

	public double getConsumptionOutOfTown() {
		return consumptionOutOfTown;
	}

	public void setConsumptionOutOfTown(double consumptionOutOfTown) {
		this.consumptionOutOfTown = consumptionOutOfTown;
	}

	public double getConsumptionCombine() {
		return consumptionCombine;
	}

	public void setConsumptionCombine(double consumptionCombine) {
		this.consumptionCombine = consumptionCombine;
	}
	
	
	/**
	 * Computed average consumption
	 * @return average consumption
	 */
	public double getAverageConsumption()
	{
		double start = 4;
		double end = 8;
		double random = new Random().nextDouble();
		double result = start + (random * (end - start));
		
		return result;
	}
	
	
	/**
	 * Get total coast for car
	 * @return total coast
	 */
	public double getTotalCoast()
	{
		double start = 50;
		double end = 10000;
		double random = new Random().nextDouble();
		double result = start + (random * (end - start));
		
		return result;
	}
}
